const { escape, execSql } = require('../db/mysql')
const { generatePassword } = require('../utils/crypto')

const login = async (username, password) => {
	// 生成加密密码
	password = generatePassword(password)

	password = escape(password)
	username = escape(username)

	const sql = `
		select username, realname from users where username=${username} and password=${password}
	`
	const rows = await execSql(sql)
	console.log('login data...', rows[0])
	return rows[0] || {}
	// 先使用假数据
	if (username === 'zhangsan' && password === '123') {
		return true
	}

	return false
}

exports.login = login
